<template name="putawayMoveDocRFSNInputPage">
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true" backRouterName="putawayMoveDocPage">
			<block slot="content">按SN上架 - 入口</block>
		</cu-custom>
		<view>
			<form>
				<view class="cu-form-group animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
					<view class="title">SN码：</view>
					<input placeholder="请输入SN码" name="input" v-model="myFormData.snCode" @confirm="onSubmit"></input>
					<text class="cuIcon-scan" @click="InputFocus"></text>
				</view>
				<view class="flex">
					<view class="flex-sub margin-xs radius padding">
						<view class="flex flex-direction">
							<button class="cu-btn bg-blue lg"  @click="putAwayStart">开始上架</button>
						</view>
					</view>
					<view class="flex-sub margin-xs radius padding">
						<view class="flex flex-direction">
							<button class="cu-btn bg-blue lg"  @click="onSubmit">确认</button>
						</view>
					</view>
				</view>
			</form>
		</view>
	</view>
</template>

<script>
	import crypto from '@/api/crypto.js'
	export default {
		data() {
			return {
				myFormData:{
					taskId:'',
					itemCode:'',
					itemName:'',
					packageInfo:'',
					allocateQty:'',
					toLocationCode:'',
					snCode:'',
					toLocationCode:'',
				},
				snCodeScanUrl:'/pda/snCodeSubmit',
			};
		},
		methods: {
			onSubmit() {
				if(!this.myFormData.snCode || this.myFormData.snCode.length==0){
					this.$tip.error('请填写SN码!');
					return;
				}
				this.$http.get(this.snCodeScanUrl,{params:{warehouseId:crypto.encrypt(this.$store.getters.warehouseid),snCode:crypto.encrypt(this.myFormData.snCode),workerId:crypto.encrypt(this.$store.getters.userid)}}).then(res=>{
				  if(res.data.success){
					  //清空扫描的SN码
					  this.myFormData.snCode = '';
					  uni.navigateTo({
					  	url: '/pages/wms/putawayMoveDocRFSNInputPage'
					  });
				  }else{
					 this.$tip.error(res.data.message);
				  }
				}).catch(()=>{
					this.$tip.loaded();
				});
			},
			putAwayStart(){
				uni.navigateTo({
					url: '/pages/wms/putawayMoveDocRFSNInputPage'
				});
			},
			InputFocus() {
				 let that = this;
				 // 调起条码扫描
				 uni.scanCode({
					 onlyFromCamera: true,
					 success: function (res) {
						 that.myFormData.snCode = res.result
					 }
				 });
			},
		}
	}
</script>
<style>
</style>